package com.ttbj.core.dao.redis.impl;


import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SessionCallback;
import org.springframework.stereotype.Repository;
import com.ttbj.core.dao.redis.IRedisValueBaseDao;

 

@Repository("redisValueDao")
public class ReidsValueBaseDao<T> implements IRedisValueBaseDao {
	
	@Autowired
	RedisTemplate<String, Object>  redisTemplate = null;

	
	@SuppressWarnings("unchecked")
	@Override
	public T get(final String Key) {
		SessionCallback<Object> callBack = new SessionCallback<Object>(){
			public <K, V> T execute(RedisOperations<K, V> operations) throws DataAccessException {
				return (T) operations.boundValueOps((K) Key).get();
			}
		};
		return  (T) redisTemplate.execute(callBack);
	}


	@SuppressWarnings("unchecked")
	@Override
	public void set(final String Key, final Object t) {
		SessionCallback<T> callBack = new SessionCallback<T>(){
			public <K, V> T execute(RedisOperations<K, V> operations) throws DataAccessException {
 			 operations.boundValueOps((K) Key).set((V) t);
				return  null;
			}
		};
		redisTemplate.execute(callBack);
	}

 

	@Override
	public void del(String key) {
		redisTemplate.delete(key);
	}


	@Override
	public void delAll(List list) {
		redisTemplate.delete(list);
	}
	
 
	 
}


